<?php
!function_exists("adminmsg") && exit("Forbidden");

$partner = md5($db_siteid.$db_siteownerid);
!$action && $action = 'blooming';
include_once(D_P.'data/bbscache/info_class.php');
include_once(D_P.'data/bbscache/info_group.php');

if ($action == 'blooming') {
	require_once(R_P.'require/posthost.php');
	InitGP(array('step'));
	$_POST['step'] = $step;
	if (empty($_POST['step'])) {

		$_Ginfo = explode(',',$db_appginfo);

		if (!file_exists(D_P.'data/bbscache/info_class.php')) {
			$verify = md5($db_sitehash.$partner.'getclass');
			$data = PostHost("http://app.phpwind.com/pw_app.php?", "action=getclass&sitehash=$db_sitehash&&verify=$verify&", "POST");

			$backdata = substr($data,strpos($data,'$backdata=')+10);
			if (strpos($backdata,'Not Found') !== false) {
				Showmsg('The Interface is not exist');
			}
			if (strpos($backdata,'}') === false) {
				$backdata = pwConvert($backdata,$db_charset,'gbk');
				Showmsg($backdata);
			}
			$backdatadb = unserialize(stripslashes($backdata));
			$backdatadb = pwConvert($backdatadb,$db_charset,'gbk');
			UpdateClassCache($backdatadb,true);
		}

	} elseif ($_POST['step'] == '2') {

		InitGP(array('ciddb'),'P');
		foreach ($info_class as $key => $value) {
			$info_class[$key]['ifshow']= '0';
		}
		foreach ($ciddb as $val) {
			$info_class[$val]['ifshow']= '1';
		}
		UpdateClassCache($info_class);

		adminmsg('operate_success');

	} elseif ($_POST['step'] == '3') {

		InitGP(array('groupdb'),'P',2);
		$groupdb = implode(',',$groupdb);
		$db->update("REPLACE INTO pw_config SET " . pwSqlSingle(array('db_name' => 'db_appginfo', 'db_value' => $groupdb)));
		updatecache_c();

		adminmsg('operate_success');

	} elseif ($_POST['step'] == '4') {

		$verify = md5($db_sitehash.$partner.'getclass');
		$data = PostHost("http://app.phpwind.com/pw_app.php?", "action=getclass&sitehash=$db_sitehash&&verify=$verify&", "POST");
		$backdata = substr($data,strpos($data,'$backdata=')+10);
		if (strpos($backdata,'Not Found') !== false) {
			Showmsg('The Interface is not exist');
		}
		if (strpos($backdata,'}') === false) {
			$backdata = pwConvert($backdata,$db_charset,'gbk');
			Showmsg($backdata);
		}
		$backdatadb = unserialize(stripslashes($backdata));
		$backdatadb = pwConvert($backdatadb,$db_charset,'gbk');
		UpdateClassCache($backdatadb,true);
		adminmsg('operate_success');
	}
}
require PrintHack("admin");exit;

function UpdateClassCache($classdb=array(),$flag=false) {
	global $info_class;
	$classcache = "<?php\r\n\$info_class=array(\r\n";

	foreach ($classdb as $key => $class) {

		!$class['ifshow'] && $class['ifshow'] = '0';
		$flag && $info_class[$class['cid']]['ifshow'] && $class['ifshow'] = '1';

		$class['name'] = str_replace(array('"',"'"),array("&quot;","&#39;"),$class['name']);
		$classcache .= "'$class[cid]'=>".pw_var_export($class).",\r\n\r\n";
	}
	$classcache .= ");\r\n?>";
	writeover(D_P."data/bbscache/info_class.php",$classcache);
}
?>